﻿using System;

namespace DuckFlyWithInterface
{
    abstract class Duck
    {
        public string Name { get; set; }
        public IFlyBehavior flyBehavior { get; set; }
        public IQuackBehavior quackBehavior { get; set; }
        public ISwimBehavior swimBehavior { get; set; }

        public void Display()
        {
            Console.WriteLine("这是一只{0}", Name);
        }

        public void PerformFly()
        {
            flyBehavior.Fly();
        }

        public void PerformQuack()
        {
            quackBehavior.Quack();
        }

        public void PerformSwim()
        {
            swimBehavior.Swim();
        }

        public void ChangeFlyBehavior(IFlyBehavior fl)
        {
            flyBehavior = fl;
        }

        public void ChangeQuackBehavior(IQuackBehavior qb)
        {
            quackBehavior = qb;
        }

        public void ChangeSwimBehavior(ISwimBehavior sb)
        {
            swimBehavior = sb;
        }
    }

    class Shelduck : Duck
    {
        public Shelduck()
        {
            Name = "Shelduck";
            flyBehavior = new FlyWithWings();
            quackBehavior = new NormalQuack();
            swimBehavior = new NormalSwim();
        }
    }

    class RedheadDuck : Duck
    {
        public RedheadDuck()
        {
            Name = "RedheadDuck";
            flyBehavior = new FlyWithWings();
            quackBehavior = new NormalQuack();
            swimBehavior = new NormalSwim();
        }
    }

    class RobberDuck : Duck
    {
        public RobberDuck()
        {
            Name = "RobberDuck";
            flyBehavior = new FlyWithNoWay();
            quackBehavior = new MuteQuack();
            swimBehavior = new CannotSwim();
        }
    }
}